<style type="text/css">
    #txtAddress1.form-control:focus,
    #txtAddress1.ng-invalid.ng-touched,
    #txtAddress2.form-control:focus,
    #txtAddress2.ng-invalid.ng-touched
    {
        z-index: 2;
    }
    
    #txtAddress1,
    #txtAddress2 {
        position: relative;
    }
    
    #txtAddress1 {
        border-bottom-left-radius: 0px; 
        border-bottom-right-radius: 0px; 
        margin-bottom:-1px;
    }
    
    #txtAddress2 {
        border-top-left-radius: 0px; 
        border-top-right-radius: 0px;
    }
</style>

<h4>Patients</h4>
<div id="alertContainer"></div>

<div class="btn-group" role="group" aria-label="Patient Controls">
    <button type="button" id="btnSelectAll" class="btn btn-default" data-toggle="button" aria-pressed="false" autocomplete="off">
        <span ng-class="{'glyphicon glyphicon-check': selectAll.selected, 'glyphicon glyphicon-unchecked': !selectAll.selected}"></span>
    </button>
	<button type="button" class="btn btn-default" ng-click="createPatient()" data-toggle="modal" data-target="#dlgEditPatient">
        <span class="glyphicon glyphicon-plus"></span>
	</button>
	<button type="button" class="btn btn-default" data-toggle="modal" data-target="#dlgDeletePatients">
        <span class="glyphicon glyphicon-trash"></span>
	</button>
</div>

<table class="table table-striped table-hover" ng-table="tableParameters">
    <tbody>
        <tr ng-repeat="patient in $data">
            <td>
                <div class="checkbox">
                    <input type="checkbox" ng-model="patient.selected" ng-change="updateSelectAll()" style="margin: 0px !important; display: inline-block;" />
                </div>
            </td>
            <td>
                <button class="btn btn-default" ng-click="editPatient(patient.id)" data-toggle="modal" data-target="#dlgEditPatient" style="margin-right: 10px;">
                    <span class="glyphicon glyphicon-pencil"></span> Edit
                </button>
                <button class="btn btn-danger" ng-click="setPatient(patient)" data-toggle="modal" data-target="#dlgDeletePatient">
                    <span class="glyphicon glyphicon-trash"></span> Delete
                </button>
            </td>
            <td data-title="'First Name'" sortable="'fName'">{{ patient.fName }}</td>
            <td data-title="'Middle Initial'" style="text-align: center;" sortable="'middleInitial'">{{ patient.middleInitial }}</td>
            <td data-title="'Last Name'" sortable="'lName'">{{ patient.lName }}</td>
            <td data-title="'Date Added'" style="text-align: center;" sortable="'dateAdded'">{{ patient.dateAdded | date: 'dd-MMM-yyyy' }}</td>
        </tr>
    </tbody>
</table>
 
<div class="modal fade" id="dlgDeletePatient" tabindex="-1" role="dialog" aria-labelledby="dlgDeletePatientTitle" aria-hidden="true">
	<div class="modal-dialog">
        <div class="modal-content">
            <form id="deletePatientForm">
	            <div class="modal-header">
				    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
				        <span aria-hidden="true">&times;</span>
				    </button>
				    
				    <h4 class="modal-title" id="dlgDeletePatientTitle">Delete Patient</h4>
				</div>
				
				<div class="modal-body">
				    <strong>Confirm!</strong> Are you sure you wish to delete this patient?
				</div>
				
				<div class="modal-footer">
				    <button type="button" class="btn btn-default" data-dismiss="modal" ng-model="button">Cancel</button>
				    <button type="button" class="btn btn-danger" aria-label="Delete" ng-click="deletePatient()" data-dismiss="modal">
				        <span class="glyphicon glyphicon-trash"></span>
				        Delete
				    </button>
	            </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="dlgDeletePatients" tabindex="-1" role="dialog" aria-labelledby="dlgDeletePatientsTitle" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form id="deletePatientsForm">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    
                    <h4 class="modal-title" id="dlgDeletePatientsTitle">Delete Patient(s)</h4>
                </div>
                
                <div class="modal-body">
                    <strong>Confirm!</strong> Are you sure you wish to delete the following patient(s)?
                    <table class="table">
                        <thead>
	                        <th>First Name</th>
	                        <th>Middle Initial</th>
	                        <th>Last Name</th>
                        </thead>
                        <tbody>
                            <tr ng-repeat="patient in selectedPatients()">
                                <td>{{ patient.fName }}</td>
                                <td>{{ patient.middleInitial }}</td>
                                <td>{{ patient.lName }}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" ng-model="button">Cancel</button>
                    <button type="button" class="btn btn-danger" aria-label="Delete" ng-click="deletePatients()" data-dismiss="modal">
                        <span class="glyphicon glyphicon-trash"></span>
                        Delete
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="dlgEditPatient" tabindex="-1" role="dialog" aria-labelledby="dlgEditPatientModalTitle" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form id="editPatientForm" name="editPatientForm">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    
                    <h4 class="modal-title" id="dlgEditPatientModalTitle">{{ mode }} Patient</h4>
                </div>
                
                <div class="modal-body">
					<div class="alert alert-danger" role="alert" ng-show="errorMessages.length > 0">
					    <ul>
					        <li ng-repeat="error in errorMessages"><strong>{{ error.label }}</strong> {{ error.message }}</li>
					    </ul>
					</div>
					<tabset>
					   <tab heading="Basic Info.">
							<div class="form-group">
							    <label for="txtFirstName" class="control-label">First Name</label>
							    <input type="text" id="txtFirstName" name="txtFirstName" class="form-control" ng-model="editingPatient.fName" maxlength="40" required />
							</div>
							<div class="form-group">
							    <label for="txtMiddleInitial" class="control-label">Middle Initial</label>
							    <input type="text" id="txtMiddleInitial" name="txtMiddleInitial" class="form-control" ng-model="editingPatient.middleInitial" maxlength="1" />
							</div>
							<div class="form-group">
							    <label for="txtLastName" class="control-label">Last Name</label>
							    <input type="text" id="txtLastName" name="txtLastName" class="form-control" ng-model="editingPatient.lName" maxlength="40" required />
							</div>
							<div class="form-group">
		                        <label for="ddlGender" class="control-label">Gender</label>
		                        <select id="ddlGender" name="ddlGender" class="form-control" ng-model="editingPatient.gender" ng-options="genderOption.value as genderOption.label for genderOption in genderOptions"></select>
		                    </div>
		                    <div class="form-group">
                                <label for="txtDateAdded" class="control-label">Date Added</label>
                                <div class="input-group">
                                    <input type="text" id="txtDateAdded" name="txtDateAdded" class="form-control" datepicker-popup ng-model="editingPatient.dateAdded" is-open="datePicker.opened" close-text="{{ datePicker.closeText }}" required />
                                    <span class="input-group-btn">
                                        <button class="btn btn-default" ng-click="openDatePicker($event)" type="button"><span class="glyphicon glyphicon-calendar"></span></button>
                                    </span>
                                </div>
                            </div>
							<div class="form-group">
		                           <label for="txtPhone" class="control-label">Phone #</label>
		                           <input type="text" id="txtPhone" name="txtPhone" class="form-control" ng-model="editingPatient.phone" ui-mask="(999) 999-9999" required />
							</div>
							<div class="form-group">
							    <label class="control-label">Address</label>
							    <label class="sr-only" for="txtAddress1">Address 1</label>
							    <input type="text" id="txtAddress1" name="txtAddress1" class="form-control" aria-label="Address 1" placeholder="Address 1" ng-model="editingPatient.address1" maxlength="40" required />
							    <label class="sr-only" for="txtAddress2">Address 2</label>
							    <input type="text" id="txtAddress2" name="txtAddress2" class="form-control" aria-label="Address 2" placeholder="Address 2" ng-model="editingPatient.address2" maxlength="40" />
							</div>
							<div class="form-group">
							    <label for="txtPassword1" class="control-label">Password</label>
							    <input type="password" id="txtPassword1" name="txtPassword1" class="form-control" ng-model="editingPatient.passw1" maxlength="40" required />
							</div>
							<div class="form-group">
							    <label for="txtPassword2" class="control-label">Confirm Password</label>
							    <input type="password" id="txtPassword2" name="txtPassword2" class="form-control" ng-model="editingPatient.passw2" maxlength="40" required />
							</div>
						</tab>
						<tab heading="Insurance">
                            <h4>Insurance Info.</h4>
                        </tab>
					</tabset>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" ng-model="button">Close</button>
                    <button type="button" class="btn btn-success" aria-label="Save" ng-click="savePatient()">
                        <span class="glyphicon glyphicon-save"></span>
                        Save
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>